import { throttle } from "@/utils";
import nocache from '@/store/nocache';

/**
 * 是否触底
 */
export const useScrollBottom = () => {
    const piniaNocache = nocache();

    const bottomingOut = throttle((e: any) => {
        let st = window.pageYOffset || document.documentElement.scrollTop || e.target.scrollTop;
        let windowHeight = window.innerHeight || document.documentElement.clientHeight || e.target.clientHeight;
        let scrollHeight = e.target.scrollHeight || document.documentElement.scrollHeight;
        if (st + windowHeight >= scrollHeight - 50) {
            console.log("触底")
            piniaNocache.setHitBottom();
        }
    }, 0.3);
    onMounted(() => {
        // 触底
        window.addEventListener('scroll', bottomingOut);
    });
    onUnmounted(() => {
        window.removeEventListener('scroll', bottomingOut);
    });
}